package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * SaaS详情页底部操作
 *
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/1/25 19:12
 * @since v1.0
 */
@Getter
public enum MobileDetailBottomOperationEnum {

    // 客户
    CUSTOMER_PUSH_NOTIFY(RedundantTemplateTypeEnum.CUSTOMER.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.customer_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    CUSTOMER_COMMUNICATE(RedundantTemplateTypeEnum.CUSTOMER.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.customer_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),
    CUSTOMER_CONTACT(RedundantTemplateTypeEnum.CUSTOMER.getCode(), "contact", "enum.mobileDetailBottomOperation.value.customer_contact", "list", XbbRefTypeEnum.CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.CUSTOMER_VIEW.getAlias()),
    CUSTOMER_LOCATION(RedundantTemplateTypeEnum.CUSTOMER.getCode(), "location", "enum.mobileDetailBottomOperation.value.customer_location", "detail", XbbRefTypeEnum.LOCATION.getCode(), IconEnum.LOCATION.getIcon(), ProPermissionAliasEnum.CUSTOMER_VIEW.getAlias()),

    // 合同
    CONTRACT_PUSH_NOTIFY(RedundantTemplateTypeEnum.CONTRACT.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.contract_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    CONTRACT_COMMUNICATE(RedundantTemplateTypeEnum.CONTRACT.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.contract_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),

    // 联系人
    CONTACT_COMMUNICATE(RedundantTemplateTypeEnum.CONTACT.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.contract_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),
    CONTACT_CONTACT(RedundantTemplateTypeEnum.CONTACT.getCode(), "contact", "enum.mobileDetailBottomOperation.value.contact_contact", "list", XbbRefTypeEnum.CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.CONTACT_VIEW.getAlias()),

    // 机会
    OPPORTUNITY_PUSH_NOTIFY(RedundantTemplateTypeEnum.SALES_OPPORTUNITY.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.opportunity_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    OPPORTUNITY_COMMUNICATE(RedundantTemplateTypeEnum.SALES_OPPORTUNITY.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.opportunity_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),

    // 应收款
    PAYMENT_PAYMENT_SHEET(RedundantTemplateTypeEnum.PAYMENT.getCode(), "paymentSheet", "enum.mobileDetailBottomOperation.value.payment_payment_sheet", "new", XbbRefTypeEnum.PAYMENT_SHEET.getCode(), "", ProPermissionAliasEnum.PAYMENT_UPDATE.getAlias()),
    PAYMENT_INVOICE(RedundantTemplateTypeEnum.PAYMENT.getCode(), "invoice", "enum.mobileDetailBottomOperation.value.payment_invoice", "new", XbbRefTypeEnum.INVOICE.getCode(), "", ProPermissionAliasEnum.INVOICE_ADD.getAlias()),

    // 付款计划
    PAY_PLAN_SHEET(RedundantTemplateTypeEnum.PAY_PLAN.getCode(), "payPlanSheet", "enum.mobileDetailBottomOperation.value.pay_plan_sheet", "new", XbbRefTypeEnum.PAY_SHEET.getCode(), "", ProPermissionAliasEnum.PAY_PLAN_UPDATE.getAlias()),

    // 供应商
    SUPPLIER_PUSH_NOTIFY(RedundantTemplateTypeEnum.SUPPLIER.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.supplier_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    SUPPLIER_COMMUNICATE(RedundantTemplateTypeEnum.SUPPLIER.getCode(), "supplierCommunicate", "enum.mobileDetailBottomOperation.value.supplier_communicate", "new", XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),
    SUPPLIER_CONTACT(RedundantTemplateTypeEnum.SUPPLIER.getCode(), "supplierContact", "enum.mobileDetailBottomOperation.value.supplier_contact", "list", XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.SUPPLIER_VIEW.getAlias()),

    // 采购合同
    PURCHASE_PUSH_NOTIFY(RedundantTemplateTypeEnum.PURCHASE.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.purchase_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    PURCHASE_COMMUNICATE(RedundantTemplateTypeEnum.PURCHASE.getCode(), "supplierCommunicate", "enum.mobileDetailBottomOperation.value.purchase_communicate", "new", XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.SUPPLIER_COMMUNICATE_ADD.getAlias()),

    //工单
    WORK_ORDER_DING(RedundantTemplateTypeEnum.WORKORDER.getCode(), "ding" , "DING", "new", XbbRefTypeEnum.DING.getCode(), IconEnum.DING.getIcon(), null),
    WORK_ORDER_LOCATION(RedundantTemplateTypeEnum.WORKORDER.getCode(), "location", "enum.mobileDetailBottomOperation.value.work_order_location", "detail", XbbRefTypeEnum.LOCATION.getCode(), IconEnum.LOCATION.getIcon(), null),
    WORK_ORDER_CONTACT(RedundantTemplateTypeEnum.WORKORDER.getCode(), "contact", "enum.mobileDetailBottomOperation.value.work_order_contact", "list", XbbRefTypeEnum.CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.WORK_ORDER_VIEW.getAlias()),
    WORK_ORDER_DYNAMIC(RedundantTemplateTypeEnum.WORKORDER.getCode(), "dynamic", "enum.mobileDetailBottomOperation.value.work_order_dynamic", "new", XbbRefTypeEnum.DYNAMIC.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.WORK_ORDER_VIEW.getAlias()),
    WORK_ORDER_OPERATION(RedundantTemplateTypeEnum.WORKORDER.getCode(), "operation", "enum.mobileDetailBottomOperation.value.work_order_operation", "list", XbbRefTypeEnum.WORK_ORDER_OPERATION.getCode(), IconEnum.WORK_ORDER.getIcon(), ProPermissionAliasEnum.WORK_ORDER_VIEW.getAlias()),

    //报价单
    QUOTATION_PUSH_NOTIFY(RedundantTemplateTypeEnum.QUOTATION.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.quotation_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    QUOTATION_COMMUNICATE(RedundantTemplateTypeEnum.QUOTATION.getCode(), "supplierCommunicate", "enum.mobileDetailBottomOperation.value.purchase_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),

    COMMUNICATE_PLAN_CONTACT(RedundantTemplateTypeEnum.COMMUNICATE_PLAN.getCode(), "contact", "enum.mobileDetailBottomOperation.value.communicate_plan_contact", "list", XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.COMMUNICATE_PLAN_VIEW.getAlias()),
    COMMUNICATE_PLAN_FINISH(RedundantTemplateTypeEnum.COMMUNICATE_PLAN.getCode(), "finish", "enum.mobileDetailBottomOperation.value.communicate_plan_finish", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.FINISH.getIcon(), ProPermissionAliasEnum.COMMUNICATE_PLAN_UPDATE.getAlias()),
    COMMUNICATE_PLAN_CANCLE(RedundantTemplateTypeEnum.COMMUNICATE_PLAN.getCode(), "cancle", "enum.mobileDetailBottomOperation.value.communicate_plan_cancle", "detail", XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), IconEnum.CANCLE.getIcon(), ProPermissionAliasEnum.COMMUNICATE_PLAN_UPDATE.getAlias()),
    COMMUNICATE_PLAN_DELAY(RedundantTemplateTypeEnum.COMMUNICATE_PLAN.getCode(), "delay", "enum.mobileDetailBottomOperation.value.communicate_plan_delay", "detail", XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), IconEnum.DELAY.getIcon(), ProPermissionAliasEnum.COMMUNICATE_PLAN_UPDATE.getAlias()),
    //预收款余额核销的权限由回款单的新建控制
    PREPAYMENT_BALANCE_UPDATE(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_ADD.getAlias(), "enum.mobileDetailBottomOperation.value.prepayment_balance_update", "new", XbbRefTypeEnum.WRITE_OFF_PREPAYMENT.getCode(), IconEnum.DELAY.getIcon(),  ProPermissionAliasEnum.PAYMENT_SHEET_ADD.getAlias()),
    //红冲的权限在回款单
    PREPAYMENT_BALANCE_RED(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_RED.getAlias(), "enum.mobileDetailBottomOperation.value.prepayment_balance_red", "new", XbbRefTypeEnum.RED_PREPAYMENT.getCode(), IconEnum.DELAY.getIcon(), ProPermissionAliasEnum.PAYMENT_SHEET_RED.getAlias()),
    PREPAYMENT_BALANCE_DEL(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_DELETE.getAlias(), "enum.mobileDetailBottomOperation.value.prepayment_balance_del", "delete", XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), IconEnum.DELAY.getIcon(), ProPermissionAliasEnum.PAYMENT_SHEET_DELETE.getAlias()),
    //预付款余额核销的权限由付款单的新建控制
    PREPAY_BALANCE_UPDATE(XbbRefTypeEnum.PREPAY_BALANCE.getCode(), ProPermissionAliasEnum.PAY_SHEET_ADD.getAlias(), "enum.mobileDetailBottomOperation.value.prepay_balance_update", "new", XbbRefTypeEnum.WRITE_OFF_PREPAY.getCode(), IconEnum.DELAY.getIcon(),  ProPermissionAliasEnum.PAY_SHEET_ADD.getAlias()),
    //红冲的权限在付款单
    PREPAY_BALANCE_RED(XbbRefTypeEnum.PREPAY_BALANCE.getCode(), ProPermissionAliasEnum.PAY_SHEET_RED.getAlias(), "enum.mobileDetailBottomOperation.value.prepay_balance_red", "new", XbbRefTypeEnum.RED_PREPAY.getCode(), IconEnum.DELAY.getIcon(), ProPermissionAliasEnum.PAY_SHEET_RED.getAlias()),
    PREPAY_BALANCE_DEL(XbbRefTypeEnum.PREPAY_BALANCE.getCode(), ProPermissionAliasEnum.PAY_SHEET_DELETE.getAlias(), "enum.mobileDetailBottomOperation.value.prepay_balance_del", "delete", XbbRefTypeEnum.PREPAY_BALANCE.getCode(), IconEnum.DELAY.getIcon(), ProPermissionAliasEnum.PAY_SHEET_DELETE.getAlias()),
    //线索
    CLUE_PUSH_NOTIFY(RedundantTemplateTypeEnum.CLUE.getCode(), "pushNotify", "enum.mobileDetailBottomOperation.value.customer_push_notify", "new", XbbRefTypeEnum.PUSH_NOTIFY.getCode(), IconEnum.NOTIFY.getIcon(), null),
    CLUE_COMMUNICATE(RedundantTemplateTypeEnum.CLUE.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.customer_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.CUSTOMER_COMMUNICATE_ADD.getAlias()),
    CLUE_CONTACT(RedundantTemplateTypeEnum.CLUE.getCode(), "contact", "enum.mobileDetailBottomOperation.value.customer_contact", "list", XbbRefTypeEnum.CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.CLUE_VIEW.getAlias()),
    CLUE_LOCATION(RedundantTemplateTypeEnum.CLUE.getCode(), "location", "enum.mobileDetailBottomOperation.value.customer_location", "detail", XbbRefTypeEnum.LOCATION.getCode(), IconEnum.LOCATION.getIcon(), ProPermissionAliasEnum.CLUE_VIEW.getAlias()),

    //回款计划
    PAYMENT_TASK_CONTACT(RedundantTemplateTypeEnum.PAYMENT_TASK.getCode(), "contact", "enum.mobileDetailBottomOperation.value.payment_task_contact", "list", XbbRefTypeEnum.PAYMENT_TASK.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.PAYMENT_TASK_VIEW.getAlias()),
    PAYMENT_TASK_FINISH(RedundantTemplateTypeEnum.PAYMENT_TASK.getCode(), "finish", "enum.mobileDetailBottomOperation.value.payment_task_finish", "new", XbbRefTypeEnum.PAYMENT_SHEET.getCode(), IconEnum.FINISH.getIcon(), ProPermissionAliasEnum.PAYMENT_TASK_UPDATE.getAlias()),

    // 经销商
    DISTRIBUTOR_COMMUNICATE(RedundantTemplateTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.customer_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.DISTRIBUTOR_COMMUNICATE_ADD.getAlias()),
    DISTRIBUTOR_CONTACT(RedundantTemplateTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode(), "contact", "enum.mobileDetailBottomOperation.value.customer_contact", "list", XbbRefTypeEnum.CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.DISTRIBUTOR_CONTACT_VIEW.getAlias()),
    DISTRIBUTOR_LOCATION(RedundantTemplateTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode(), "location", "enum.mobileDetailBottomOperation.value.customer_location", "detail", XbbRefTypeEnum.LOCATION.getCode(), IconEnum.LOCATION.getIcon(), ProPermissionAliasEnum.DISTRIBUTOR_VIEW.getAlias()),

    // 经销商联系人
    DISTRIBUTOR_CONTACT_COMMUNICATE(RedundantTemplateTypeEnum.DISTRIBUTOR_CONTACT.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.distributor_communicate", "new", XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.DISTRIBUTOR_COMMUNICATE_ADD.getAlias()),
    DISTRIBUTOR_CONTACT_CONTACT(RedundantTemplateTypeEnum.DISTRIBUTOR_CONTACT.getCode(), "contact", "enum.mobileDetailBottomOperation.value.distributor_contact", "list", XbbRefTypeEnum.DISTRIBUTOR_CONTACT.getCode(), IconEnum.CONTACT.getIcon(), ProPermissionAliasEnum.DISTRIBUTOR_CONTACT_VIEW.getAlias()),

    // 订货单
    ORDER_COMMUNICATE(RedundantTemplateTypeEnum.ORDER.getCode(), "customerCommunicate", "enum.mobileDetailBottomOperation.value.contract_communicate", "new", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), IconEnum.COMMUNICATE.getIcon(), ProPermissionAliasEnum.DISTRIBUTOR_COMMUNICATE_ADD.getAlias()),

    ;

    private Integer fromBusinessType;
    private String attr;
    private String value;
    private String btnType;
    private Integer businessType;
    private String icon;
    private String color;
    private String permission;

    MobileDetailBottomOperationEnum(Integer fromBusinessType, String attr, String value, String btnType, Integer businessType, String icon, String permission) {
        this.fromBusinessType = fromBusinessType;
        this.businessType = businessType;
        this.attr = attr;
        this.value = value;
        this.btnType = btnType;
        this.icon = icon;
        this.permission = permission;
    }

    /**
     * 获取dingtalk详情页底部操作
     *
     * @param businessType 业务
     * @return List
     * @author GuoJun.HU
     * @date 2019/3/21 15:30
     * @since V1.0
     */
    public static List<MobileDetailBottomOperationEnum> getByBusinessType(Integer businessType) {
        List<MobileDetailBottomOperationEnum> list = new ArrayList<>();
        for (MobileDetailBottomOperationEnum bottomOperationEnum : MobileDetailBottomOperationEnum.values()) {
            if (Objects.equals(businessType, bottomOperationEnum.getFromBusinessType())) {
                list.add(bottomOperationEnum);
            }
        }
        return list;
    }

    /**
     * 获取dingtalk详情页底部操作
     *
     * @param businessType 业务
     * @return List
     * @author GuoJun.HU
     * @date 2019/3/21 15:30
     * @since V1.0
     */
    public static List<MobileDetailBottomOperationEnum> getByBusinessTypeAndPermission(Integer businessType, Set<String> permissions) {
        List<MobileDetailBottomOperationEnum> list = new ArrayList<>();
        for (MobileDetailBottomOperationEnum bottomOperationEnum : MobileDetailBottomOperationEnum.values()) {
            boolean hasPermission = true;
            if (Objects.nonNull(bottomOperationEnum.getPermission())) {
                hasPermission = permissions.contains(bottomOperationEnum.getPermission());
            }
            if (Objects.equals(businessType, bottomOperationEnum.getFromBusinessType()) && hasPermission) {
                list.add(bottomOperationEnum);
            }
        }
        return list;
    }

    public String getValue() {
        return I18nMessageUtil.getMessage(value);
    }
}
